package com.tgy.config;

import org.aopalliance.intercept.Interceptor;
import org.springframework.boot.autoconfigure.web.WebProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;

/***
 * @ClassName: MyMvcConfig
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 15:36 2021/12/24
 * @version : V1.0
 */

//如果你想DIY一些定制得功能，只要写这个组件，然后将他交给SpringBoot,然后SpringBoot就会帮我们自动装配
//DispatcherServlet
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }
/*    //ViewResolver 实现了视图解析器接口得类我们就叫做视图解析器
    @Bean
    public MyViewResolver myViewResolver(){
        return new MyViewResolver();
    };

    //自定义得视图解析器
    public static class MyViewResolver implements ViewResolver{

        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {
            return null;
        }
    }*/

    //根目录在这里配置
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandle()).addPathPatterns("/*").excludePathPatterns("/index.html","/","/user/login","/static/*");
    }
}
